package leetcode_501_600;

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;

public class LeeCode_503 {
    public static void main(String[] args) {

    }
    private static int[] nextGreaterElements(int[] nums) {
        int n = nums.length;
        int[] ans = new int[n];
        Arrays.fill(ans, -1);
        Deque<Integer> queue = new LinkedList<>();
        for (int i = 0; i < 2 * n - 1; i++) {
            while (!queue.isEmpty() && nums[queue.peek()] < nums[i % n]){
                ans[queue.pop()] = nums[i % n];
            }
            queue.push(i % n);
        }
        return ans;
    }
}
